package com.hsjk.szwj.module.official.controller.admin.unit;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleDiyCreateReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleDiyDetailRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleDiyPageReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleDiyPageRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleDiyUpdateReqVO;
import com.hsjk.szwj.module.official.service.unit.IUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/11/24 00:25
 **/
@Tag(name = "后台管理端 - 官网模块化金刚区相关接口")
@RestController
@RequestMapping("/official-website/unit/diy")
@Validated
public class AdminUnitDiyController {
    @Resource
    private IUnitService unitService;

    @PostMapping("/create")
    @Operation(summary = "新增金刚区")
    @PreAuthorize("@ss.hasPermission('official-website:unit:diy:create')")
    public CommonResult<Boolean> createModuleDiy(@RequestBody @Valid AdminModuleDiyCreateReqVO reqVO) {
        return success(unitService.createModuleDiy(reqVO));
    }

    @GetMapping("/get-diy-by-id")
    @Operation(summary = "根据金刚区id获取金刚区详情")
    @PreAuthorize("@ss.hasPermission('official-website:unit:diy:query')")
    public CommonResult<AdminModuleDiyDetailRespVO> getAdminModuleDiyDetail(@RequestParam Long id) {
        return success(unitService.getAdminModuleDiyDetail(id));
    }

    @PostMapping("/update")
    @Operation(summary = "更改金刚区")
    @PreAuthorize("@ss.hasPermission('official-website:unit:diy:update')")
    public CommonResult<Boolean> updateModuleDiy(@RequestBody @Valid AdminModuleDiyUpdateReqVO reqVO) {
        return success(unitService.updateModuleDiy(reqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除金刚区")
    @PreAuthorize("@ss.hasPermission('official-website:unit:diy:delete')")
    public CommonResult<Boolean> deleteModuleDiy(@RequestParam("id") Long id) {
        return success(unitService.deleteModuleDiy(id));
    }

    @PostMapping("/page")
    @Operation(summary = "金刚区分页查询")
    @PreAuthorize("@ss.hasPermission('official-website:unit:diy:query')")
    public CommonResult<PageResult<AdminModuleDiyPageRespVO>> getAdminModuleDiyPage(@RequestBody @Valid AdminModuleDiyPageReqVO reqVO) {
        return success(unitService.getAdminModuleDiyPage(reqVO));
    }
}
